//顶部商品数量
var user = document.querySelectorAll(".shop .user")
var shul = user.length
    //console.log(shul)
var poi = document.querySelector(".shul")
poi.innerHTML = shul



//        总价
var zong = document.querySelectorAll(".zong")
var loi = document.querySelector(".end .endj")
var js = 0
for (var y = 0; y < zong.length; y++) {
    var ji = zong[y].innerHTML
    ji = Number(ji)
        //            console.log(ji)
    js = js + ji
        //            console.log(js)
}
js = js.toFixed(2)
loi.innerHTML = js



//        删除操作
var shanchu = document.querySelectorAll(".shan p")
var shop = document.querySelector(".shop")
for (var k = 0; k < shanchu.length; k++) {
    shanchu[k].addEventListener('click', function () {
        //        console.log(this.parentNode.parentNode)
        shop.removeChild(this.parentNode.parentNode)
            //        顶部商品数量
        var user = document.querySelectorAll(".shop .user")
        var shul = user.length
            //        console.log(shul)
        var poi = document.querySelector(".shul")
        poi.innerHTML = shul
            //        总价
        var zong = document.querySelectorAll(".zong")
        var loi = document.querySelector(".end .endj")
        var js = 0
        for (var y = 0; y < zong.length; y++) {
            var ji = zong[y].innerHTML
            ji = Number(ji)
                //            console.log(ji)
            js = js + ji
                //            console.log(js)
        }
        js = js.toFixed(2)
        loi.innerHTML = js
    })
}


//输入框数量变化
var input = document.querySelectorAll(".input")
for (var i = 0; i < input.length; i++) {
    input[i].addEventListener('change', function () {
        //        获取单价
        var jis = this.parentNode.parentNode.children[2].lastElementChild.innerHTML
        var jio = this.parentNode.parentNode.children[4].children[2].innerHTML 
                    console.log(jio)
            //        console.log(jis)
            //        获取数量值
            //        console.log(this.value)
            //        小计
        var po = jis * this.value
        var to = jio*this.value
        po = po.toFixed(2)
        to=to.toFixed(2)
            //        console.log(po)
        this.parentNode.parentNode.children[4].firstElementChild.innerHTML = po
        this.parentNode.parentNode.children[4].children[1].innerHTML = to
            //        总价
        var loi = document.querySelector(".end .endj")
        var zong = document.querySelectorAll(".zong")
        var js = 0
        for (var y = 0; y < zong.length; y++) {
            var ji = zong[y].innerHTML
            ji = Number(ji)
                //            console.log(ji)
            js = js + ji
                //            console.log(js)
        }
        js = js.toFixed(2)
        loi.innerHTML = js
    })
}